package plugin.cs2java.utils;

import com.intellij.openapi.vfs.VirtualFile;
import org.apache.commons.httpclient.util.EncodingUtil;

public class FileUtil {
    public static String getText(VirtualFile file) {
        try {
            byte[] bytes = file.contentsToByteArray();
            return EncodingUtil.getString(bytes, "utf-8");
        } catch (Exception ex) {
            return ex.getMessage();
        }
    }

    public static void setText(VirtualFile file, String text) {
        try {
            byte[] bytes = EncodingUtil.getBytes(text, "utf-8");
            file.setBinaryContent(bytes);
        } catch (Exception ex) {
            //Logger.getGlobal().warning(ex.getMessage());
        }
    }
}
